<#--
List of variables to be passed for this template:
        +- rootPackage
        +- applicationName
        +- classNames
        +- directory
        +- Entities: ArrayList of EntityClass.getAsMap()

            |
            +- imports: imports
            |
            +- name: The name of the class.
            |    |
            |    +- single
            |    +- plural
            |
            +- idColumn: the id column
            |    |
            |    +- field
            |    |    |
            |    |    +- name
            |    |    +- type
            |    |
            |    +- getter
            |    +- setter
            |
            +- columns: ArrayList of columns
            |    |
            |    +- field
            |    |    |
            |    |    +- name
            |    |    +- type
            |    |    +- hasTypeParameter
            |    |    +- typeParameter -- only if hasTypeParameter returns true!
            |    +- getter
            |    +- setter

-->
<@pp.dropOutputFile />
<@pp.changeOutputFile name="/development/${directory}/GWT/${directory}/client/apis/utils/JavaScriptArray.java" />

package ${rootPackage}.${applicationName}.client.apis.utils;

import java.util.ArrayList;
import java.util.Collection;

import com.google.gwt.core.client.JavaScriptObject;

public class JavaScriptArray<E extends JavaScriptObject> extends
		JavaScriptObject {

	protected JavaScriptArray() {
	};

	public final native int length() /*-{
		return this.length;
	}-*/;

	public final native E pop() /*-{
		return this.pop();
	}-*/;

	public final native int push(E element) /*-{
		return this.push(element);
	}-*/;

	public final native E get(int i) /*-{
		return this[i];
	}-*/;

	public final JavaScriptArray<E> fromCollection(Collection<E> collection)
	{
		for(E element : collection)
		{
			this.push(element);
		}
		return this;
	}

	public final Collection<E> toCollection()
	{
		Collection<E> collection = new ArrayList<E>();
		for(int i=0; i<this.length(); i++)
		{
			collection.add(this.get(i));
		}
		return collection;
	}
}
